# Maintainer: Daniel Bermond <dbermond@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>

pkgname=intel-graphics-compiler
epoch=1
pkgver=1.0.13463.18
pkgrel=1
pkgdesc="Intel Graphics Compiler for OpenCL"
arch=(loong64 x86_64)
url="https://github.com/intel/intel-graphics-compiler"
license=(MIT)
depends=(llvm-libs intel-opencl-clang ncurses spirv-tools zlib lld)
makedepends=(git cmake clang llvm python libunwind spirv-headers vc-intrinsics)
options=(!emptydirs)
source=(${url}/archive/igc-${pkgver}.tar.gz)
sha256sums=('0b960878a5feffd6aa10197c48bf73a0a3a19d0105428d48163e91db0444070a')

build() {
  export CXXFLAGS="${CXXFLAGS/-Wp,-D_GLIBCXX_ASSERTIONS}"

  cmake -B build -S ${pkgname}-igc-${pkgver} \
    -G 'Unix Makefiles' \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DIGC_OPTION__ARCHITECTURE_TARGET='Linux64' \
    -DIGC_OPTION__CLANG_MODE=Prebuilds \
    -DIGC_OPTION__LINK_KHRONOS_SPIRV_TRANSLATOR=ON \
    -DIGC_OPTION__LLD_MODE=Prebuilds \
    -DIGC_OPTION__LLVM_MODE=Prebuilds \
    -DIGC_OPTION__LLVM_PREFERRED_VERSION='15.0.7' \
    -DIGC_OPTION__SPIRV_TOOLS_MODE=Prebuilds \
    -DIGC_OPTION__SPIRV_TRANSLATOR_MODE=Prebuilds \
    -DIGC_OPTION__USE_PREINSTALLED_SPRIV_HEADERS=ON \
    -DIGC_OPTION__VC_INTRINSICS_MODE=Prebuilds \
    -DINSTALL_GENX_IR=ON \
    -Wno-dev
  cmake --build build
}

package() {
  DESTDIR="${pkgdir}" cmake --install build
  install -D -m644 ${pkgname}-igc-${pkgver}/LICENSE.md -t "${pkgdir}"/usr/share/licenses/${pkgname}
  mv "${pkgdir}"/usr/lib/igc/NOTICES.txt "${pkgdir}"/usr/share/licenses/${pkgname}
}
